<?php
	session_start();
	require('../Gen_Scripts/gen_functions.php');

	$game_no = $_GET['game_no'];
	$zoom = $_GET['zoom'];

	dblogin();
	$maxes =
	"select max(t.game_no) as \"MAX_NBR\"
	  from TOURNY t";
	$result = mysql_query($maxes);
	if($row = mysql_fetch_array($result)){
		if($game_no=='' || $game_no > $row['MAX_NBR']){
			$game_no = $row['MAX_NBR'];
		}
	}
	if($game_no <= 0){
		$game_no = 1;
	}
	
	
	
	
?>

<script type="text/javascript">
$(document).ready(function(){
	$('.localhover').cluetip({
		tracking: false,
		splitTitle: '|',
		showTitle: false,
		cluetipClass: 'jtip',
		sticky: false,
		dropShadow: false
	});
	
	$('.pload').click(function(){
		$('#player_ajax').load('Points/player_info.php',{player_id: $(this).attr('name')});
		$('#life_ajax').load('Points/life_info.php',{player_id: $(this).attr('name')});
		return false;
	});

});
</script>

<?php
	if($zoom=='GAME'){
?>
	<div id="gp_by_game" class="full left">	
		<img class="arrow pointer right" src="images/right_arrow.png"  onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no+1;?>&zoom=GAME")' type="button" />		
		<img class="arrow pointer left" src="images/left_arrow.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no-1;?>&zoom=GAME")' type="button" />		
		<h1> Game # <?php echo $game_no; ?> </h1>
		<table>
		<?php
			dblogin();
			$totals =
			"select p.player_id, ifnull(g.type,'NONE') as \"TYPE\", sum(g.amount) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
				and g.game_no =".$game_no."
			 group by p.player_id, g.type";
			$result = mysql_query($totals);
			while($row = mysql_fetch_array($result)){
				$gp_by_game[$row['player_id']][$row['TYPE']] = $row['AMOUNT'];
			}
			$player_q =
			"select p.player_id, sum(ifnull(g.amount,0)) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
				and g.game_no =".$game_no."
			 group by p.player_id";
			$result = mysql_query($player_q);
			while($row = mysql_fetch_array($result)){
				$players_by_game[$row['player_id']]	= $row['AMOUNT'];
			}
			arsort($players_by_game);		
			$max_amt = 0;
			foreach($players_by_game as $player => $amt){
				if($max_amt < $amt){
					$max_amt = $amt;
				}
				$fill = 1;
				if($max_amt > 0){
					$fill = floor(450/$max_amt);
				}
		?>
			<tr>
				<td><a href="#" name="<?php echo $player; ?>" class="pload"> <?php echo player_name($player);?> </a></td>
				<td> <div id="stats" style="width:<?php echo $amt*$fill;?>px">
						<div class="stat bad localhover" style="width: <?php if(isset($gp_by_game[$player]['BAD'])){echo $gp_by_game[$player]['BAD']*$fill;}else{echo 0;}?>px"
																title="<?php if(isset($gp_by_game[$player]['BAD'])){echo $gp_by_game[$player]['BAD'];}else{echo 0;}?>"></div>
						<div class="stat rsvp localhover" style="width:<?php if(isset($gp_by_game[$player]['RSVP'])){echo $gp_by_game[$player]['RSVP']*$fill;}else{echo 0;}?>px"
																title="<?php if(isset($gp_by_game[$player]['RSVP'])){echo $gp_by_game[$player]['RSVP'];}else{echo 0;}?>"></div>
						<div class="stat bring_item localhover" style="width:<?php if(isset($gp_by_game[$player]['ITEM'])){echo $gp_by_game[$player]['ITEM']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['ITEM'])){echo $gp_by_game[$player]['ITEM'];}else{echo 0;}?>"></div>
						<div class="stat bring_food localhover" style="width:<?php if(isset($gp_by_game[$player]['FOOD'])){echo $gp_by_game[$player]['FOOD']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['FOOD'])){echo $gp_by_game[$player]['FOOD'];}else{echo 0;}?>"></div>
						<div class="stat submitted localhover" style="width:<?php if(isset($gp_by_game[$player]['SUB'])){echo $gp_by_game[$player]['SUB']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['SUB'])){echo $gp_by_game[$player]['SUB'];}else{echo 0;}?>"></div>
						<div class="stat win localhover" style="width:<?php if(isset($gp_by_game[$player]['WIN'])){echo $gp_by_game[$player]['WIN']*$fill;}else{echo 0;}?>px"
																title=" <?php if(isset($gp_by_game[$player]['WIN'])){echo $gp_by_game[$player]['WIN'];}else{echo 0;}?>"></div>
						<div class="stat from_game localhover" style="width:<?php if(isset($gp_by_game[$player]['GP'])){echo $gp_by_game[$player]['GP']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['GP'])){echo $gp_by_game[$player]['GP'];}else{echo 0;}?>"></div>
					</div></td>
				<td> <?php echo $amt; ?> </td>
			</tr>
		<?php
			}
		?>
		</table>
		<img class="pointer right" src="images/minimize.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no;?>")' type="button" />		
	</div>
<?php
	}else if($zoom=='OVERALL'){
?>
	<div id="gp_overall" class="full left">
		<h1> Overall GP </h1>
		<table>
		<?php
			dblogin();
			$totals =
			"select p.player_id, ifnull(g.type,'NONE') as \"TYPE\", sum(g.amount) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
			 group by p.player_id, g.type";
			$result = mysql_query($totals);
			while($row = mysql_fetch_array($result)){
				$gp[$row['player_id']][$row['TYPE']] = $row['AMOUNT'];
			}
			$player_q =
			"select p.player_id, sum(ifnull(g.amount,0)) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
			 group by p.player_id";
			$result = mysql_query($player_q);
			while($row = mysql_fetch_array($result)){
				$players[$row['player_id']]	= $row['AMOUNT'];
			}
			arsort($players);		
			$max_amt = 0;
			foreach($players as $player => $amt){
				if($max_amt < $amt){
					$max_amt = $amt;
				}
				$fill = 1;
				if($max_amt > 0){
					$fill = floor(450/$max_amt);
				}
		?>
			<tr>
				<td><a href="#" name="<?php echo $player; ?>" class="pload"> <?php echo player_name($player);?> </a></td>
				<td> <div id="stats" style="width:<?php echo $amt*$fill;?>px">
						<div class="stat bad localhover"  title="<?php if(isset($gp[$player]['BAD'])){echo $gp[$player]['BAD'];}else{echo 0;}?>"  
								            style="width: <?php if(isset($gp[$player]['BAD'])){echo $gp[$player]['BAD']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat rsvp localhover" title="<?php if(isset($gp[$player]['RSVP'])){echo $gp[$player]['RSVP'];}else{echo 0;}?>" 
									        style="width: <?php if(isset($gp[$player]['RSVP'])){echo $gp[$player]['RSVP']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat bring_item localhover" title="<?php if(isset($gp[$player]['ITEM'])){echo $gp[$player]['ITEM'];}else{echo 0;}?>"  
										          style="width: <?php if(isset($gp[$player]['ITEM'])){echo $gp[$player]['ITEM']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat bring_food localhover" title="<?php if(isset($gp[$player]['FOOD'])){echo $gp[$player]['FOOD'];}else{echo 0;}?>"  
									              style="width: <?php if(isset($gp[$player]['FOOD'])){echo $gp[$player]['FOOD']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat submitted localhover" title="<?php if(isset($gp[$player]['SUB'])){echo $gp[$player]['SUB'];}else{echo 0;}?>" 
								                 style="width: <?php if(isset($gp[$player]['SUB'])){echo $gp[$player]['SUB']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat win localhover" title="<?php if(isset($gp[$player]['WIN'])){echo $gp[$player]['WIN'];}else{echo 0;}?>"  
									       style="width: <?php if(isset($gp[$player]['WIN'])){echo $gp[$player]['WIN']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat from_game localhover" title="<?php if(isset($gp[$player]['GP'])){echo $gp[$player]['GP'];}else{echo 0;}?>"  
										         style="width: <?php if(isset($gp[$player]['GP'])){echo $gp[$player]['GP']*$fill;}else{echo 0;}?>px"></div>
					</div></td>
				<td> <?php echo $amt; ?> </td>
			</tr>
		<?php
			}
		?>
		</table>
		<img class="pointer right" src="images/minimize.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no;?>")' type="button" />		
	</div>
<?php	
	}else{
	/**  Normal viewing  **/
?>
	<div id="gp_overall" class="split left">
		<h1> Overall GP </h1>
		<table>
		<?php
			dblogin();
			$totals =
			"select p.player_id, ifnull(g.type,'NONE') as \"TYPE\", sum(g.amount) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
			 group by p.player_id, g.type";
			$result = mysql_query($totals);
			while($row = mysql_fetch_array($result)){
				$gp[$row['player_id']][$row['TYPE']] = $row['AMOUNT'];
			}
			$player_q =
			"select p.player_id, sum(ifnull(g.amount,0)) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
			 group by p.player_id";
			$result = mysql_query($player_q);
			while($row = mysql_fetch_array($result)){
				$players[$row['player_id']]	= $row['AMOUNT'];
			}
			arsort($players);		
			$max_amt = 0;
			foreach($players as $player => $amt){
				if($max_amt < $amt){
					$max_amt = $amt;
				}
				$fill = 1;
				if($max_amt > 0){
					$fill = floor(200/$max_amt);
				}
		?>
			<tr>
				<td><a href="#" name="<?php echo $player; ?>" class="pload"> <?php echo player_name($player);?> </a></td>
				<td> <div id="stats" style="width:<?php echo $amt*$fill;?>px">
						<div class="stat bad localhover"  title="<?php if(isset($gp[$player]['BAD'])){echo $gp[$player]['BAD'];}else{echo 0;}?>"  
								            style="width: <?php if(isset($gp[$player]['BAD'])){echo $gp[$player]['BAD']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat rsvp localhover" title="<?php if(isset($gp[$player]['RSVP'])){echo $gp[$player]['RSVP'];}else{echo 0;}?>" 
									        style="width: <?php if(isset($gp[$player]['RSVP'])){echo $gp[$player]['RSVP']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat bring_item localhover" title="<?php if(isset($gp[$player]['ITEM'])){echo $gp[$player]['ITEM'];}else{echo 0;}?>"  
										          style="width: <?php if(isset($gp[$player]['ITEM'])){echo $gp[$player]['ITEM']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat bring_food localhover" title="<?php if(isset($gp[$player]['FOOD'])){echo $gp[$player]['FOOD'];}else{echo 0;}?>"  
									              style="width: <?php if(isset($gp[$player]['FOOD'])){echo $gp[$player]['FOOD']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat submitted localhover" title="<?php if(isset($gp[$player]['SUB'])){echo $gp[$player]['SUB'];}else{echo 0;}?>" 
								                 style="width: <?php if(isset($gp[$player]['SUB'])){echo $gp[$player]['SUB']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat win localhover" title="<?php if(isset($gp[$player]['WIN'])){echo $gp[$player]['WIN'];}else{echo 0;}?>"  
									       style="width: <?php if(isset($gp[$player]['WIN'])){echo $gp[$player]['WIN']*$fill;}else{echo 0;}?>px"></div>
						<div class="stat from_game localhover" title="<?php if(isset($gp[$player]['GP'])){echo $gp[$player]['GP'];}else{echo 0;}?>"  
										         style="width: <?php if(isset($gp[$player]['GP'])){echo $gp[$player]['GP']*$fill;}else{echo 0;}?>px"></div>
					</div></td>
				<td> <?php echo $amt; ?> </td>
			</tr>
		<?php
			}
		?>
		</table>
		<img class="pointer right" src="images/maximize.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no;?>&zoom=OVERALL")' type="button" />		
	</div>
	<div id="gp_by_game" class="split right">
		<img class=" arrow pointer right" src="images/right_arrow.png"  onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no+1;?>")' type="button" />		
		<img class=" arrow pointer left" src="images/left_arrow.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no-1;?>")' type="button" />		
		<h1> Game # <?php echo $game_no; ?> </h1>
		<table>
		<?php
			dblogin();
			$totals =
			"select p.player_id, ifnull(g.type,'NONE') as \"TYPE\", sum(g.amount) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
				and g.game_no =".$game_no."
			 group by p.player_id, g.type";
			$result = mysql_query($totals);
			while($row = mysql_fetch_array($result)){
				$gp_by_game[$row['player_id']][$row['TYPE']] = $row['AMOUNT'];
			}
			$player_q =
			"select p.player_id, sum(ifnull(g.amount,0)) as \"AMOUNT\"
			  from PLAYERS p
			  left outer join GAMEPT g
			    on p.player_id = g.player_id
				and g.game_no =".$game_no."
			 group by p.player_id";
			$result = mysql_query($player_q);
			while($row = mysql_fetch_array($result)){
				$players_by_game[$row['player_id']]	= $row['AMOUNT'];
			}
			arsort($players_by_game);		
			$max_amt = 0;
			foreach($players_by_game as $player => $amt){
				if($max_amt < $amt){
					$max_amt = $amt;
				}
				$fill = 1;
				if($max_amt > 0){
					$fill = floor(200/$max_amt);
				}
		?>
			<tr>
				<td><a href="#" name="<?php echo $player; ?>" class="pload"> <?php echo player_name($player);?> </a></td>
				<td> <div id="stats" style="width:<?php echo $amt*$fill;?>px">
						<div class="stat bad localhover" style="width: <?php if(isset($gp_by_game[$player]['BAD'])){echo $gp_by_game[$player]['BAD']*$fill;}else{echo 0;}?>px"
																title="<?php if(isset($gp_by_game[$player]['BAD'])){echo $gp_by_game[$player]['BAD'];}else{echo 0;}?>"></div>
						<div class="stat rsvp localhover" style="width:<?php if(isset($gp_by_game[$player]['RSVP'])){echo $gp_by_game[$player]['RSVP']*$fill;}else{echo 0;}?>px"
																title="<?php if(isset($gp_by_game[$player]['RSVP'])){echo $gp_by_game[$player]['RSVP'];}else{echo 0;}?>"></div>
						<div class="stat bring_item localhover" style="width:<?php if(isset($gp_by_game[$player]['ITEM'])){echo $gp_by_game[$player]['ITEM']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['ITEM'])){echo $gp_by_game[$player]['ITEM'];}else{echo 0;}?>"></div>
						<div class="stat bring_food localhover" style="width:<?php if(isset($gp_by_game[$player]['FOOD'])){echo $gp_by_game[$player]['FOOD']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['FOOD'])){echo $gp_by_game[$player]['FOOD'];}else{echo 0;}?>"></div>
						<div class="stat submitted localhover" style="width:<?php if(isset($gp_by_game[$player]['SUB'])){echo $gp_by_game[$player]['SUB']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['SUB'])){echo $gp_by_game[$player]['SUB'];}else{echo 0;}?>"></div>
						<div class="stat win localhover" style="width:<?php if(isset($gp_by_game[$player]['WIN'])){echo $gp_by_game[$player]['WIN']*$fill;}else{echo 0;}?>px"
																title=" <?php if(isset($gp_by_game[$player]['WIN'])){echo $gp_by_game[$player]['WIN'];}else{echo 0;}?>"></div>
						<div class="stat from_game localhover" style="width:<?php if(isset($gp_by_game[$player]['GP'])){echo $gp_by_game[$player]['GP']*$fill;}else{echo 0;}?>px" 
																title="<?php if(isset($gp_by_game[$player]['GP'])){echo $gp_by_game[$player]['GP'];}else{echo 0;}?>"></div>
					</div></td>
				<td> <?php echo $amt; ?> </td>
			</tr>
		<?php
			}
		?>
		</table>
		<img class="pointer right" src="images/maximize.png" onClick='$("#left_pane").load("Points/summary_info.php?game_no=<?php echo $game_no;?>&zoom=GAME")' type="button" />		
</div>
<?php 
	}
?>
